package com.huanghao.Service.impl;

import java.sql.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huanghao.Service.CommodService;
import com.huanghao.mapper.CommodMapper;
import com.huanghao.pojo.Commod;
import com.huanghao.pojo.PageBean;

@Service
public class CommodServiceimpl implements CommodService{

    @Autowired
    private CommodMapper empMapper;
    
    //删除
    @Override
    public void delete(List<Integer> id) {
        empMapper.deleteByid(id);
    }
    
    //添加
    @Override
    public void add(Commod emp) {
        empMapper.insert(emp);
    }

	
	//数据更新
    @Override
    public void update(Commod emp) {
        empMapper.update(emp); 
    }
    
    //根据ID查询
    @Override
    public Commod getById(Integer id) {
        return empMapper.getById(id);
    }

    //分页查询
	@Override
	public PageBean page(Integer page, Integer pageSize, String cName, Integer cNumber, Integer cPrice, Integer cSales,
			Date begin,Date end, Integer cInventory) {
		System.out.println(page + " : " + pageSize);
        //设置分页参数
        PageHelper.startPage(page,pageSize);
        //执行查询
        List<Commod> empList = empMapper.list(cName,cNumber,cPrice,cSales,begin,end,cInventory);
        System.out.println(empList);
        Page<Commod> p = (Page<Commod>) empList;
        //封装PageBean
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
	}

}